package com.codemonkey.lq.qd.db.support;

public class PageParameter {

	//默认每页行数
	public static final int DEFAULT_PAGE_SIZE = 10;

	//每页行数
    private int pageSize;
    //当前页码
    private int currentPage;
    //上一页
    private int prePage;
    //下一页
    private int nextPage;
    //总页码数
    private int totalPage;
    //总记录数
    private int totalCount;
    //当前页开始位置
    private int startIndex;
    //当前页结束位置
    private int endIndex;

    public int getStartIndex() {
    	startIndex = (currentPage - 1) * pageSize;
		return startIndex;
	}

	public void setStartIndex(int startIndex) {
		this.startIndex = startIndex;
	}

	public int getEndIndex() {
		endIndex = currentPage * pageSize;
		return endIndex;
	}

	public void setEndIndex(int endIndex) {
		this.endIndex = endIndex;
	}

	public PageParameter() {
        //this.pageSize = DEFAULT_PAGE_SIZE;
    }

    /**
     * 
     * @param currentPage
     * @param pageSize
     */
    public PageParameter(int currentPage, int pageSize) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
    }

    public int getCurrentPage() {
    	if(currentPage < 1){
    		currentPage = 1;
    	}
    	if(currentPage > totalPage){
    		currentPage = totalPage;
    	}
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getPrePage() {
        prePage = this.currentPage - 1;
        if(prePage < 1){
        	prePage = this.currentPage;
        }
    	return prePage;
    }

    public void setPrePage(int prePage) {
        this.prePage = prePage;
    }

    public int getNextPage() {
    	nextPage = this.currentPage + 1;
    	if(nextPage > this.totalPage){
    		nextPage = this.totalPage;
    	}
        return nextPage;
    }

    public void setNextPage(int nextPage) {
        this.nextPage = nextPage;
    }

    public int getTotalPage() {
    	if(totalCount % pageSize == 0){
    		totalPage = totalCount / pageSize;
    	}else{
    		totalPage = totalCount / pageSize + 1;
    	}
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }
}
